package com.itheima.d4_collections;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/*
    目标：斗地主游戏的案例开发。
    业务需求分析:
        业务: 总共有54张牌。
        点数: "3","4","5","6","7","8","9","10","J","Q","K","A","2"
        花色: "♠", "♥", "♣", "♦"
        大小王: "👲" , "🃏"
        点数分别要组合4种花色，大小王各一张。
        斗地主：发出51张牌，剩下3张作为底牌。
 */
public class GameDemo {
    public static void main(String[] args) {
        //创建牌
        String[] numbers = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
        String[] colors = {"♠", "♥", "♣", "♦"};
        int size = 0;
        //创建集合存放牌
        ArrayList<Card> cards = new ArrayList<>();
        for (String number : numbers) {
            size++;
            for (String color :colors){
                Card card = new Card(number,color,size);
                cards.add(card);
            }
        }
        Card graykcard = new Card("","🃏",++size);
        Card redkcard = new Card("","👲",++size);
        Collections.addAll(cards,graykcard,redkcard);
        System.out.println(cards);
        //洗牌
        Collections.shuffle(cards);
        System.out.println("洗牌后:"+ cards);
        //发牌
        List<Card> chengliuxiang = new ArrayList<>();
        List<Card> bolochuixue = new ArrayList<>();
        List<Card> luxiaoguo = new ArrayList<>();
        for (int i =0;i<cards.size()-3;i++) {
            Card c = cards.get(i);
            if(i%3==0){
                chengliuxiang.add(c);
            }
            if(i%3==1){
                bolochuixue.add(c);
            }
            if(i%3==2){
                luxiaoguo.add(c);
            }
        }
        //排序
        Collections.sort(chengliuxiang, new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                return o2.getSize() - o1.getSize();
            }
        });
        Collections.sort(bolochuixue, new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                return o1.getSize() - o2.getSize();
            }
        });
        Collections.sort(luxiaoguo, new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                return o1.getColor().compareTo(o2.getColor());
            }
        });
        System.out.println("==================================");
        System.out.println("橙留香的牌：" + chengliuxiang);
        System.out.println("菠萝吹雪的牌：" + bolochuixue);
        System.out.println("陆小果的牌：" + luxiaoguo);
        List<Card> cards1 = cards.subList(cards.size()-3,cards.size());
        System.out.println("底牌：" + cards1);
        System.out.println("==================================");
        //抢地主
        luxiaoguo.addAll(cards1);
        Collections.sort(luxiaoguo, new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                return o1.getColor().compareTo(o2.getColor());
            }
        });
        System.out.println("陆小果的地主牌：" + luxiaoguo);

    }
}










